<template>
  <div class="header">
    <hamburger :is-active="opened" class="hamburger-container" @toggleClick="toggleSideBar"/>
    <breadcrumb class="breadcrumb-container"/>
    <div class="right-menu">
      <el-dropdown class="avatar-container" trigger="click">
        <div class="avatar-wrapper">
          <span style="margin-right: 5px;">{{user.name}}</span>
          <i class="el-icon-more"></i>
        </div>
        <template #dropdown>
          <el-dropdown-menu class="user-dropdown">
            <router-link to="/">
              <el-dropdown-item>
                首页
              </el-dropdown-item>
            </router-link>
            <el-dropdown-item divided>
              <span style="display:block;" @click="logout">退出</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import Hamburger from "./Hamburger";
import Breadcrumb from "./Breadcrumb";
import {loginOut} from "../api/login/index";
import {ref} from "vue";
import store from "../store/index"
import {success} from "../util/tipsUtils";
import router from "../router";
import {getUser} from "../util/userUtils";
export default {
  name: "Header",
  components: {
    Hamburger,
    Breadcrumb
  },
  setup() {
    const opened = ref(store.getters.getAsideStatus);
    const toggleSideBar = () => {
      opened.value = !opened.value;
      store.commit("toggleAsideStatus");
    }
    const logout = () => {
      loginOut()
      success("登出成功")
      router.push("/login")
    }
    const user = getUser()
    return {
      opened,
      toggleSideBar,
      user,
      logout
    };
  }
};
</script>

<style scoped lang="scss">
.header {
  background: #ffffff;
  overflow: hidden;
  position: relative;
  /*box-shadow: 0 1px 4px rgba(0,21,41,.08);*/
  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;
    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }
  .breadcrumb-container {
    float: left;
  }
  .right-menu {
    float: right;
    height: 100%;
    &:focus {
      outline: none;
    }
    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;
      &.hover-effect {
        cursor: pointer;
        transition: background .3s;
        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }
    .avatar-container {
      margin-right: 30px;
      .avatar-wrapper {
        position: relative;
        cursor: pointer;
        margin: 0;
        padding: 0 10px;
        span {
          line-height: 50px;
        }
        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
